/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controlador;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author CORE i5
 */
public class ControladorHotel {
    //Registrar deportista
    public int guardar(String id, String nombre, String direccion, String telefono, String paginaWeb) {
        Hotel h = new Hotel();
        h.setCodigo(id);
        h.setNombre(nombre);
        h.setDireccion(direccion);
        h.setTelefono(telefono);
        h.setPaginaWeb(paginaWeb);
        try {
            daoHotel.create(h);
            return -1;
        } catch (PreexistingEntityException ex) {
            Logger.getLogger(ProgramaController.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(ProgramaController.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }

    public int borrar(String id) {
        try {
            daoHotel.destroy(id);
            return -1;
        } catch (IllegalOrphanException ex) {
            Logger.getLogger(ProgramaController.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NonexistentEntityException ex) {
            Logger.getLogger(ProgramaController.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }

    public void modificar(String codigo, String nombre, String nivel, int numCreditos) {

        Programa p = daoPrograma.findPrograma(codigo);
        p.setNombre(nombre);
        p.setNivel(nivel);
        p.setNumCreditos(numCreditos);

        try {
            daoPrograma.edit(p);
        } catch (IllegalOrphanException ex) {
            Logger.getLogger(ProgramaController.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NonexistentEntityException ex) {
            Logger.getLogger(ProgramaController.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(ProgramaController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Hotel consultar(String id) {
        Hotel p = daoHotel.findHotel(id);
        return p;
    }

    public List<Hotel> consultarTodo() {
        List<Hotel> Hoteles = daoHotel.findHotelEntities();
        return Hoteles;
    }
}
